<template>
  <div class="birthday">
    <van-datetime-picker
      v-model="currentDate"
      type="date"
      :min-date="minDate"
      :max-date="maxDate">
    </van-datetime-picker>
  </div>
</template>

<script>
  import {NavBar, Button, DatetimePicker, Toast} from 'vant';

  export default {
    name: "Birthday",
    components: {
      [NavBar.name]: NavBar,
      [Button.name]: Button,
      [DatetimePicker.name]: DatetimePicker,
      [Toast.name]: Toast,
    },
    data() {
      return {
        currentDate: new Date(2000, 0, 1),
        minDate: new Date(1900, 0, 1),
        maxDate: new Date(),
      }
    },
    props: ["icon"],
    methods: {
      setMsg() {
        let _this = this;
        let time = _this.currentDate.getTime() / 1000;
        let data = _this.$qs.stringify({
          'birthday': time
        });
        let token = _this.getCookie("token");
        _this.$http.post(_this.apiUrl("user/users/setInfo"), data, {headers: {'token': token}}).then((res) => {
          // console.log(res.data);
          let code = res.data.statusCode;
          if (code === 200) {
            Toast.success('修改成功！');
            _this.returnFlag(true);
          }
          else{
            _this.returnFlag(false);
            Toast.fail('修改失败！');
          }
        });
      },
      changeStyle(){
        let v = document.getElementsByClassName("van-picker__toolbar");
        v[0].style.display = "none";
      },
      returnFlag(flag) {
        let _this = this;
        if (flag) {
          _this.$emit("giveFlag", _this.randomWord(true, 10, 20));
        }
        else {
          _this.$emit("giveFlag", "null");
        }
      },
      getData(){
        let _this = this;
        let str= []; //定义一数组
        str=_this.icon.split("-"); //字符分割
        _this.currentDate = new Date(str[0], str[1] - 1, str[2]);
      }
    },
    mounted(){
      let _this = this;
      _this.changeStyle();
      setTimeout(function () {
        _this.getData();
      }, 300);
    }
  }
</script>

<style scoped>
</style>
